package applications.studentApplicationForm.ui.lib;

import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.Font;
import java.awt.GridLayout;
import java.util.Observable;

import javax.swing.BorderFactory;
import javax.swing.BoxLayout;
import javax.swing.JComponent;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.SpringLayout;
import javax.swing.SwingConstants;

import ontocompo.lib.PartialBorder;
import ontocompo.lib.SpringUtilities;
import ontocompo.lib.PartialBorder.Side;

import org.objectweb.fractal.fraclet.annotations.Component;
import org.objectweb.fractal.fraclet.annotations.Interface;
import org.objectweb.fractal.fraclet.annotations.Requires;

import applications.studentApplicationForm.fc.api.StudentForm;

@Component(provides = {@Interface(name = "jPanelItf", signature = org.objectweb.fractal.swing.JPanelItf.class),@Interface(name = "observer", signature = java.util.Observer.class), @Interface(name = "jPanelAttributes", signature = org.objectweb.fractal.swing.JPanelAttributes.class), @Interface(name = "uicontainerservice", signature = ontocompo.api.UIContainerService.class), @Interface(name = "ontocompointrospection", signature = ontocompo.api.OntoCompoIntrospection.class)})

public class StudentApplicationFormStudentPersonalDataButton extends JPanel implements java.util.Observer, org.objectweb.fractal.swing.JPanelItf, org.objectweb.fractal.swing.JPanelAttributes, ontocompo.api.UIContainerService, ontocompo.api.OntoCompoIntrospection {


	private String uid;
	private org.objectweb.fractal.api.Component c;

	@Requires(name = "studentapplicationformgenderlabel")
	private ontocompo.api.UIContainerService studentapplicationformgenderlabel;

	@Requires(name = "studentapplicationformgendervalue")
	private ontocompo.api.UIContainerService studentapplicationformgendervalue;



	@Requires(name = "studentapplicationformstudentnumberlabel")
	private ontocompo.api.UIContainerService studentapplicationformstudentnumberlabel;

	@Requires(name = "studentapplicationformstudentnumbervalue")
	private ontocompo.api.UIContainerService studentapplicationformstudentnumbervalue;



	@Requires(name = "studentapplicationformiNELabel")
	private ontocompo.api.UIContainerService studentapplicationformiNELabel;

	@Requires(name = "studentapplicationformIneValue")
	private ontocompo.api.UIContainerService studentapplicationformIneValue;




	@Requires(name = "studentapplicationformfamilynamelabel")
	private ontocompo.api.UIContainerService studentapplicationformfamilynamelabel;

	@Requires(name = "studentapplicationformfamilynamevalue")
	private ontocompo.api.UIContainerService studentapplicationformfamilynamevalue;




	@Requires(name = "studentapplicationformfirstNameLabel")
	private ontocompo.api.UIContainerService studentapplicationformfirstNameLabel;

	@Requires(name = "studentapplicationformFirstNameValue")
	private ontocompo.api.UIContainerService studentapplicationformFirstNameValue;



	@Requires(name = "studentapplicationformDateBirthLabel")
	private ontocompo.api.UIContainerService studentapplicationformDateBirthLabel;

	@Requires(name = "studentapplicationformDateBirthValue")
	private ontocompo.api.UIContainerService studentapplicationformDateBirthValue;




	@Requires(name = "studentapplicationFormEmailLabel")
	private ontocompo.api.UIContainerService studentapplicationFormEmailLabel;

	@Requires(name = "studentapplicationFormEmailValue")
	private ontocompo.api.UIContainerService studentapplicationFormEmailValue;




	@Requires(name = "studentapplicationFormNationalityLabel")
	private ontocompo.api.UIContainerService studentapplicationFormNationalityLabel;

	@Requires(name = "studentapplicationFormNationalityValue")
	private ontocompo.api.UIContainerService studentapplicationFormNationalityValue;




	@Requires(name = "studentformdirectoryservice")
	private applications.studentApplicationForm.fc.api.StudentFormDirectoryService studentformdirectoryservice;

	@Requires(name = "studentformdirectoryobservable")
	private ontocompo.api.Observable studentformdirectoryobservable;


	public StudentApplicationFormStudentPersonalDataButton() {
		super();
		this.uid = "applications.studentApplicationForm.ui.lib.StudentApplicationFormStudentPersonalDataButton";
		System.out.println(this.toString() + "created");
	}

	@Override
	public void init() {
		// TODO Auto-generated method stub

		this.studentformdirectoryobservable.addObserver(this);

		this.studentapplicationformgenderlabel.init();
		this.studentapplicationformgendervalue.init();

		this.studentapplicationformstudentnumberlabel.init();
		this.studentapplicationformstudentnumbervalue.init();

		this.studentapplicationformiNELabel.init();
		this.studentapplicationformIneValue.init();

		this.studentapplicationformfamilynamelabel.init();
		this.studentapplicationformfamilynamevalue.init();

		this.studentapplicationformfirstNameLabel.init();
		this.studentapplicationformFirstNameValue.init();


		this.studentapplicationformDateBirthLabel.init();
		this.studentapplicationformDateBirthValue.init();


		this.studentapplicationFormEmailLabel.init();
		this.studentapplicationFormEmailValue.init();

		this.studentapplicationFormNationalityLabel.init();
		this.studentapplicationFormNationalityValue.init();

		this.setBackground(Color.white);


		// 16 lignes, 2 colonnes 
		JPanel panel = new JPanel(new GridLayout(8,2,20,20));
		panel.setBackground(Color.white);


		panel.add(this.studentapplicationformgenderlabel.getComponentItSelf());
		panel.add(this.studentapplicationformgendervalue.getComponentItSelf());

		panel.add(this.studentapplicationformstudentnumberlabel.getComponentItSelf());
		panel.add(this.studentapplicationformstudentnumbervalue.getComponentItSelf());

		panel.add(this.studentapplicationformiNELabel.getComponentItSelf());
		panel.add(this.studentapplicationformIneValue.getComponentItSelf());

		panel.add(this.studentapplicationformfamilynamelabel.getComponentItSelf());
		panel.add(this.studentapplicationformfamilynamevalue.getComponentItSelf());

		panel.add(this.studentapplicationformfirstNameLabel.getComponentItSelf());
		panel.add(this.studentapplicationformFirstNameValue.getComponentItSelf());


		panel.add(this.studentapplicationformDateBirthLabel.getComponentItSelf());
		panel.add(this.studentapplicationformDateBirthValue.getComponentItSelf());


		panel.add(this.studentapplicationFormEmailLabel.getComponentItSelf());
		panel.add(this.studentapplicationFormEmailValue.getComponentItSelf());


		panel.add(this.studentapplicationFormNationalityLabel.getComponentItSelf());
		panel.add(this.studentapplicationFormNationalityValue.getComponentItSelf());



		this.add(panel);	




	}

	protected JLabel createTd(String txt)
	{
		JLabel result = new JLabel(txt);
		result.setFont(result.getFont().deriveFont(Font.PLAIN));
		result.setHorizontalAlignment(SwingConstants.LEFT);

		return result;
	}

	protected JPanel createBox(int thickness)
	{
		JPanel result = new JPanel();
		if (thickness > 0) result.setBorder(BorderFactory.createLineBorder(Color.black, thickness));
		result.setBackground(Color.white);
		return result;
	}




	@Override
	public JComponent getComponentItSelf() {
		// TODO Auto-generated method stub
		return this;
	}

	@Override
	public void update(Object o) {
		// TODO Auto-generated method stub
		
		StudentForm student = this.studentformdirectoryservice.getStudentForm();
	

		JPanel panel = new JPanel(new GridLayout(8,2,20,20));
		panel.setBackground(Color.white);
		
		

		
		if (student != null)
		{
			this.setBackground(Color.white);

			this.removeAll();

			

			this.studentapplicationformgendervalue.update(student.getGender());
			this.studentapplicationformstudentnumbervalue.update(student.getStudentNumber());
			this.studentapplicationformIneValue.update(student.getINE());
			this.studentapplicationformfamilynamevalue.update(student.getFamilyName());
			this.studentapplicationformFirstNameValue.update(student.getFirstName());
			this.studentapplicationformDateBirthValue.update(student.getDateOfBirth());
			this.studentapplicationFormEmailValue.update(student.getEmail());
			this.studentapplicationFormNationalityValue.update(student.getNationality());
			
			panel.add(this.studentapplicationformgenderlabel.getComponentItSelf());
			panel.add(this.studentapplicationformgendervalue.getComponentItSelf());

			panel.add(this.studentapplicationformstudentnumberlabel.getComponentItSelf());
			panel.add(this.studentapplicationformstudentnumbervalue.getComponentItSelf());

			panel.add(this.studentapplicationformiNELabel.getComponentItSelf());
			panel.add(this.studentapplicationformIneValue.getComponentItSelf());

			panel.add(this.studentapplicationformfamilynamelabel.getComponentItSelf());
			panel.add(this.studentapplicationformfamilynamevalue.getComponentItSelf());

			panel.add(this.studentapplicationformfirstNameLabel.getComponentItSelf());
			panel.add(this.studentapplicationformFirstNameValue.getComponentItSelf());

			panel.add(this.studentapplicationformDateBirthLabel.getComponentItSelf());
			panel.add(this.studentapplicationformDateBirthValue.getComponentItSelf());

			panel.add(this.studentapplicationFormEmailLabel.getComponentItSelf());
			panel.add(this.studentapplicationFormEmailValue.getComponentItSelf());

			panel.add(this.studentapplicationFormNationalityLabel.getComponentItSelf());
			panel.add(this.studentapplicationFormNationalityValue.getComponentItSelf());




			this.add(panel);	


			this.getParent().validate();  // pour rafraichir la page

			
		}
		


	}

	public String toString() {
		return "StudentApplicationFormStudentPersonalDataButton";
	}


	@Override
	public org.objectweb.fractal.api.Component getFractalComponent() {
		// TODO Auto-generated method stub
		return this.c;
	}

	@Override
	public String getUid() {
		// TODO Auto-generated method stub
		return this.uid;
	}

	@Override
	public void setFractalComponent(org.objectweb.fractal.api.Component c) {
		// TODO Auto-generated method stub
		this.c = c;
	}

	@Override
	public void setUid(String uid) {
		// TODO Auto-generated method stub
		this.uid = uid;
	}

	@Override
	public void update(Observable o, Object arg) {
		// TODO Auto-generated method stub
		StudentForm bk = this.studentformdirectoryservice.getStudentForm();

		if (bk == null){
			return;
		}
		else { 
			this.update(bk);
		}


	}

}
